package com.wang.mybatisdemo.controller;

import com.wang.mybatisdemo.Service.UserService;
import com.wang.mybatisdemo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {


    @Autowired
    private UserService userService;

    //插入
    @RequestMapping(value = "/add")
    @CrossOrigin
    public String add(){
        User user = new User();

        user.setUserName("test");
        user.setUserPass("123456");
        user.setUserAge(11);

        Map<String,Object> myMap = new HashMap<>();

        myMap.put("userName",user.getUserName());
        myMap.put("userPass",user.getUserPass());
        myMap.put("userAge",user.getUserAge());




        userService.add("user",myMap);

        return null;

    }
    //修改
    @RequestMapping(value = "/update")
    @CrossOrigin
    public String update(){
        User user = new User();

        user.setUserName("test11");
        user.setUserPass("12345611");
        user.setUserAge(15);

        Map<String,Object> myMap = new HashMap<>();

        myMap.put("userName",user.getUserName());
        myMap.put("userPass",user.getUserPass());
        myMap.put("userAge",user.getUserAge());

        Map<String,Object> primaryParam = new HashMap<>();

        primaryParam.put("userId",1);


        userService.update("user",primaryParam,myMap);

        return null;

    }
    //删除
    @RequestMapping(value = "/update")
    @CrossOrigin
    public String delete(){


        Map<String,Object> myMap = new HashMap<>();

        myMap.put("userName","test");
        myMap.put("userAge","11");


        Map<String,Object> primaryParam = new HashMap<>();

        primaryParam.put("userId",1);


        userService.update("user",primaryParam,myMap);

        return null;

    }






}
